package restaurant;

import java.rmi.RemoteException;

import org.apache.axis2.AxisFault;

import com.foo.servicesCall.GetAllRestaurantDataFaultException;
import com.foo.servicesCall.RestaurantServiceStub;
import com.foo.servicesCall.RestaurantServiceStub.GetAllRestaurantData;
import com.foo.servicesCall.RestaurantServiceStub.GetAllRestaurantDataResponse;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByName;
import com.foo.servicesCall.RestaurantServiceStub.GetRestaurantInfoByNameResponse;


public class RestaurantClient 
{
	private static final String SERVICE_END_POINT = 
		"http://localhost:8080/axis2/services/RestaurantService";
	
	private RestaurantServiceStub stub;
	
	public RestaurantClient()
	{
		try
		{
			stub = new RestaurantServiceStub(SERVICE_END_POINT);
		} catch (AxisFault e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

	public void getRestaurantDataByName()
	{
		try
		{
			GetRestaurantInfoByName res = new GetRestaurantInfoByName();
			res.setIn("Acapulco");
			GetRestaurantInfoByNameResponse result = new GetRestaurantInfoByNameResponse();
			result = stub.getRestaurantInfoByName(res);
			GetAllRestaurantDataResponse resu = new GetAllRestaurantDataResponse();
			GetAllRestaurantData getAllRestaurantData = new GetAllRestaurantData();
			getAllRestaurantData.setIn("");
			try
			{
				resu = stub.getAllRestaurantData(getAllRestaurantData);
			}
			catch(RemoteException e)
			{
				System.out.println(e.getMessage());
			}
			catch(GetAllRestaurantDataFaultException ex)
			{
				System.out.println(ex.getMessage());
			}
			
			if(resu != null)
			{
				
			}
			if(result.getOut() != null)
			{
				System.out.println("Restaurant Details for Name Acapulco is as follows --> \n" +
					"Restaurant Name: " +result.getOut().getRestaurant_name() + 
					"Restaurnat Location: " + result.getOut().getRestaurant_location() +
					"Restaurant Rating: " + result.getOut().getRestaurant_rating());
			}
		}
		catch(Exception e)
		{
			e.printStackTrace();
		}
	}
	
	public static void main(String[] args) {
		
		RestaurantClient client = new RestaurantClient();
		client.getRestaurantDataByName();
	}

}
